package br.puc.rio.fabio.telas;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.crypto.spec.DESedeKeySpec;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;

import br.puc.rio.fabio.CarregamentoRedeExtension;
import br.puc.rio.fabio.kruskal.ClusterPlugIn;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;

import javax.swing.table.DefaultTableModel;

import java.awt.Color;

import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;
import javax.swing.JComboBox;

public class TelaUploadFile extends JDialog {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7873224945328218193L;
	ClusterPlugIn clusterPlugIn;
	private JTextField textField_diretorioArquivo;
	
	public TelaUploadFile(ClusterPlugIn aPlugIn) {
		
		super(aPlugIn.getPlugInContext().getWorkbenchFrame(),"Importar Arquivo", false);
		setTitle("Importar Arquivo");
		this.clusterPlugIn = aPlugIn;
		
		setBounds(100, 100, 357, 218);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 73, 28, 156, 115, 80, 102, 61, 0, 0, 29, 0};
		gridBagLayout.rowHeights = new int[]{23, 26, 0, 0, 0, 115, 0, 0, 30, 0, 0, 27, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		getContentPane().setLayout(gridBagLayout);
		
		JLabel lblDefina = new JLabel("1 - Cole o diret\u00F3rio do arquivo");
		lblDefina.setForeground(Color.BLACK);
		lblDefina.setBackground(Color.ORANGE);
		GridBagConstraints gbc_lblDefina = new GridBagConstraints();
		gbc_lblDefina.anchor = GridBagConstraints.WEST;
		gbc_lblDefina.gridwidth = 5;
		gbc_lblDefina.insets = new Insets(0, 0, 5, 5);
		gbc_lblDefina.gridx = 1;
		gbc_lblDefina.gridy = 7;
		getContentPane().add(lblDefina, gbc_lblDefina);
		
		textField_diretorioArquivo = new JTextField();
		GridBagConstraints gbc_textField_diretorioArquivo = new GridBagConstraints();
		gbc_textField_diretorioArquivo.gridwidth = 6;
		gbc_textField_diretorioArquivo.insets = new Insets(0, 0, 5, 5);
		gbc_textField_diretorioArquivo.fill = GridBagConstraints.HORIZONTAL;
		gbc_textField_diretorioArquivo.gridx = 1;
		gbc_textField_diretorioArquivo.gridy = 8;
		getContentPane().add(textField_diretorioArquivo, gbc_textField_diretorioArquivo);
		textField_diretorioArquivo.setColumns(10);
		
		JLabel lblEexemploCusersfrdesktopuptxt = new JLabel("Exemplo: C:/Users/FR/Desktop/Up.txt");
		GridBagConstraints gbc_lblEexemploCusersfrdesktopuptxt = new GridBagConstraints();
		gbc_lblEexemploCusersfrdesktopuptxt.gridwidth = 6;
		gbc_lblEexemploCusersfrdesktopuptxt.insets = new Insets(0, 0, 5, 5);
		gbc_lblEexemploCusersfrdesktopuptxt.gridx = 1;
		gbc_lblEexemploCusersfrdesktopuptxt.gridy = 9;
		getContentPane().add(lblEexemploCusersfrdesktopuptxt, gbc_lblEexemploCusersfrdesktopuptxt);
		
		JButton btnCarregaArquivo = new JButton("Carregar");
		GridBagConstraints gbc_btnCarregaArquivo = new GridBagConstraints();
		gbc_btnCarregaArquivo.gridwidth = 4;
		gbc_btnCarregaArquivo.insets = new Insets(0, 0, 5, 5);
		gbc_btnCarregaArquivo.gridx = 2;
		gbc_btnCarregaArquivo.gridy = 10;
		getContentPane().add(btnCarregaArquivo, gbc_btnCarregaArquivo);
		
		JButton btn_gravarPontos = new JButton("Gravar");
		GridBagConstraints gbc_btn_gravarPontos = new GridBagConstraints();
		gbc_btn_gravarPontos.gridwidth = 4;
		gbc_btn_gravarPontos.insets = new Insets(0, 0, 5, 5);
		gbc_btn_gravarPontos.gridx = 6;
		gbc_btn_gravarPontos.gridy = 10;
		getContentPane().add(btn_gravarPontos, gbc_btn_gravarPontos);
		
		btnCarregaArquivo.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
					String arqu = textField_diretorioArquivo.getText();
					List<String> linhas = null;
					Path path = Paths.get(arqu);
					try {
						linhas = Files.readAllLines(path,StandardCharsets.UTF_8);
					} catch (IOException e) {
						System.out.println("Erro na leitura do Arquivo");
						e.printStackTrace();
					}
					
					clusterPlugIn.desenhaPontosNaCamada(linhas);
			}
		});
		
		btn_gravarPontos.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {

				
				
			}
		});
		
		
	}
}
